package main

import (
	"encoding/json"
	"fmt"
	"harbor/src/configs"
	"harbor/src/models"
	"harbor/src/service"
	"io/ioutil"
)

//"https://admin:Harbor12345@10.137.194.238/api/projects"
func main() {
	HARBOR_URL := "dockerhub.picclife.com"
	var images_tag []models.Image_tag
	harbor_proj := service.GetProject(HARBOR_URL)
	harbor_respositires := service.GetRepositories(harbor_proj, HARBOR_URL)
	//for j,t:=range harbor_respositires{
	//	fmt.Println(j,t.Name)
	//}
	var image = make([]models.Image_tag, 0)
	//
	for _, repositories := range harbor_respositires {
	LOOP:
		resp_images, _ := configs.HttpInit().Get("https://" + HARBOR_URL + "/api/repositories/" +
			repositories.Name + "/tags")

		//resp_images, _ := configs.HttpInit().Get("https://" + HARBOR_URL + "/api/repositories/hx/cbs_claim_register_web_deploy_config/tags")
		resp_images_body, _ := ioutil.ReadAll(resp_images.Body)
		err := json.Unmarshal(resp_images_body, &images_tag)
		if err != nil {
			goto LOOP
		}
		defer resp_images.Body.Close()
		for _, v := range images_tag {
			if v.Size == 0 || v.Name == "" {
				continue
			}
			ret := models.Image_tag{
				Name:   repositories.Name + ":" + v.Name,
				Size:   v.Size,
				Digest: v.Digest,
			}
			image = append(image, ret)
		}
	}
	for i, v := range image {
		fmt.Println("总images:",i, v)
	}
}
